package com.cs;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @ClassName: NIOFileChannel04
 * @Description: TODO
 * @Author: kevinHan
 * @Date: 2020/8/6 21:46
 * @Version: 1.0
 */
public class NIOFileChannel04 {
    public static void main(String[] args) throws Exception {

        // 创建流
        FileInputStream fileInputStream = new FileInputStream("d:\\1.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("d:\\2.jpg");

        // 获取各个流对应的fileChannel
        FileChannel source = fileInputStream.getChannel();
        FileChannel desth = fileOutputStream.getChannel();

        // 使用transFerForm完成拷贝
        desth.transferFrom(source, 0, source.size());

        // 关闭相关通道和流
        source.close();
        desth.close();
        fileInputStream.close();
        fileOutputStream.close();

    }
}
